package com.rn.simple.common;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * Description：自定义的类加载器
 *
 * @author rannuo
 * @date 2019/12/4
 */
public class CusClassLoader extends ClassLoader {
    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        String myPath = "file:///D:/JavaDev/IDEA_J/simple/data/MyTest.class";
        System.out.println(myPath);
        byte[] cLassBytes = null;
        Path path;
        try {
            path = Paths.get(new URI(myPath));
            cLassBytes = Files.readAllBytes(path);
        } catch (IOException | URISyntaxException e) {
            e.printStackTrace();
        }
        if (cLassBytes == null) {
            return null;
        }
        return defineClass(name, cLassBytes, 0, cLassBytes.length);
    }
}
